package com.neuedu.servletobj.config;


import com.neuedu.servletobj.component.SecondListener;
import com.neuedu.servletobj.component.SecondsServlet;
import com.neuedu.servletobj.component.SecondstFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.RegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

@Configuration
public class AppConfig {


    /**
     * 注册 Servlet
     * @return
     */
    @Bean
    ServletRegistrationBean servletRegistrationBean(){

        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();

        servletRegistrationBean.setServlet(new SecondsServlet());
        servletRegistrationBean.addUrlMappings("/second");

        return servletRegistrationBean;
    }



    @Bean
    FilterRegistrationBean filterRegistrationBean(){

        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();

        filterRegistrationBean.setFilter(new SecondstFilter());
        filterRegistrationBean.addUrlPatterns("/*");

        return filterRegistrationBean;
    }


    @Bean
    ServletListenerRegistrationBean servletListenerRegistrationBean(){

        ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean();

        servletListenerRegistrationBean.setListener(new SecondListener());

        return servletListenerRegistrationBean;
    }



}
